﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FCNS.KeepMoney.Util
{
    class DateTimeUtil
    {
        /// <summary>
        /// 计算指定月份的账单日期
        /// </summary>
        public static DateTime CalculateTheBillingDate(int year, int month)
        {
            if (Program.AppConfig.Bill.BillMode == BillsMode.Bill)
            {
                int day = Program.AppConfig.Bill.BillDay;
                while (day > DateTime.DaysInMonth(year, month))
                    day--;

                return DateTimeUtil.yyyyMMdd(year, month, day);
            }
            else
            {
                DateTime dt = DateTimeUtil.yyyyMMdd(year, month, DateTime.DaysInMonth(year, month));
                return dt;
            }
        }
        /// <summary>
        /// 设置日期为 00:00:00
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="day"></param>
        /// <returns></returns>
        public static DateTime yyyyMMdd(int year, int month, int day)
        {
            return DateTime.ParseExact(year.ToString() + month.ToString("D2") + day.ToString("D2"),
                         "yyyyMMdd", null);
        }

        public static DateTime RemoveTime(DateTime datetime)
        {
            return new DateTime(datetime.Year, datetime.Month, datetime.Day);
        }
    }
}
